package com.jzo2o.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jzo2o.health.model.domain.ReservationSetting;
import com.jzo2o.health.model.dto.response.ReservationSettingResDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

import java.time.LocalDate;

import java.time.LocalDate;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author itcast
 * @since 2023-11-01
 */
public interface ReservationSettingMapper extends BaseMapper<ReservationSetting> {
    @Update("UPDATE reservation_setting SET reservations = reservations + 1 WHERE id = #{id} AND reservations < number")
    Integer updateReservations(@Param("id") Integer id);



    /**
     * 按月查询预约设置
     * @param date
     * @return
     */
    List<ReservationSettingResDTO> getAdminReservationSettingByMonth(@Param("date") String date);

    /**
     * 按月查询可预约日期
     * @param month
     * @return
     */
    List<String> getUserReservationDateByMonth(@Param("month")String month);

    @Update("UPDATE reservation_setting SET reservations = reservations - 1 WHERE order_date = #{day} AND reservations > 0")
    void updateCount(LocalDate day);

    /**
     * 更新可预约人数
     * @param number
     * @param orderDate
     * @return
     */
    boolean updateReservationsNum(@Param("number") Integer number, @Param("orderDate")LocalDate orderDate);
    @Select("SELECT * from reservation_setting where order_date=#{reservationDate}")
    ReservationSetting selectByDate(LocalDate reservationDate);
}
